//
//  BMKCircleAnnotationView.m
//  RNIbuildModuleBaiduMap
//
//  Created by Wentao Ye on 22/05/2017.
//  Copyright © 2017 Facebook. All rights reserved.
//

#import "BMKCircleAnnotationView.h"

@implementation BMKCircleAnnotationView

-(instancetype)init{
    self = [super init];
    if (self) {
        
    }
    return  self;
}
-(id)initWithAnnotation:(id<BMKAnnotation>)annotation reuseIdentifier:(NSString *)reuseIdentifier
{
    if ((self = [super initWithAnnotation:annotation reuseIdentifier:reuseIdentifier])) {
        [self setFrame:CGRectMake(0, 0, kWidth(63), kWidth(63))];
        [self setUserInteractionEnabled:YES];
        self.backgroundColor = [UIColor clearColor];
        [self setUserInteractionEnabled:YES];
        
        self.bgImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, kWidth(63), kHeight(63.f))];
        self.bgImage.image = [UIImage imageNamed:@"map_circle"];
        
        [self addSubview:self.bgImage];
        [self.bgImage setUserInteractionEnabled:YES];
        
        self.lblName = [[UILabel alloc] initWithFrame:CGRectMake(4.f, kHeight(15.f), kWidth(63) - 8.f, kHeight(20.f))];
        self.lblName.backgroundColor = [UIColor clearColor];
        self.lblName.textAlignment = NSTextAlignmentCenter;
        self.lblName.numberOfLines = 1;
        self.lblName.textColor = [Util colorWithHexString:@"#515151"];
        self.lblName.font = [UIFont boldSystemFontOfSize:12.f];
        self.lblName.lineBreakMode = NSLineBreakByTruncatingTail;
        [self addSubview: self.lblName];
        
        
        [self.lblName setUserInteractionEnabled:YES];
        UITapGestureRecognizer *tapRecg= [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(viewTapped:)];
        [self.lblName addGestureRecognizer:tapRecg];
        
        self.lblCount = [[UILabel alloc] initWithFrame:CGRectMake(0.f, self.lblName.frame.size.height + self.lblName.frame.origin.y, kWidth(63), kHeight(10.f))];
        self.lblCount.backgroundColor = [UIColor clearColor];
        self.lblCount.textAlignment = NSTextAlignmentCenter;
        self.lblCount.numberOfLines = 1;
        self.lblCount.textColor = [Util colorWithHexString:@"#515151"];
        self.lblCount.font = [UIFont systemFontOfSize:12.f];
        self.lblCount.lineBreakMode = NSLineBreakByWordWrapping;
        
        [self addSubview: self.lblCount];
        
        [self.lblCount setUserInteractionEnabled:YES];
        UITapGestureRecognizer *tapRecg2= [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(viewTapped:)];
        [self.lblCount addGestureRecognizer:tapRecg2];
    }
    return self;
}


-(void)viewTapped:(UITapGestureRecognizer *)sender
{
    [self.delegate BMKCircleAnnotationView:self clickViewWithData:self.annotation];
}

@end
